<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link href="../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../static/js/jquery.cookie.min.js"></script>
	<script type="text/javascript" src="../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../static/vui/js/vui.js"></script>
	<script type="text/javascript" src="../../static/vui/js/treegrid.js"></script>
	<script type="text/javascript" src="../../static/js/common.js"></script>
</head>
<body>

<div id="table"></div>

<script>
    var params = app.getRequestParams();
    $(function(){


        $('#table').treegrid({
            id:'table',
            url:app.BASE_API_URL+'company/find',
            root:app.getLogin().companyParentId,
            columns:[
                {field:'name',title:'机构名称',width:150,formatter:function (row) {
					return '<a href="javascript:void(0);" onclick="selectRow(this)" class="link">'+row.name+'</a>';
				 }},
                {field:'contact',title:'联系人',fixed:true,width:70},
                {field:'contactPhone',title:'联系电话',width:150}
            ]
        });
    });

    function getOpenFrame(){
        if( params.index == -1 ){
            //当前页
            return parent;
        }else{
            //当前页的弹出页
            return parent.frames[0];
        }
    }

    function selectRow(_this) {
        var row = $(_this).parent().parent().parent().parent().data();
        var search = $('#'+params.searchId,getOpenFrame().document);
        search.find('input[type="text"]').val(row.name);
        search.find('input[type="hidden"]').val(row.id);
        app.closeLastWindow();
    }

</script>
</body>
</html>